#ifndef HTTPREQUESTPACK_H
#define HTTPREQUESTPACK_H

#include <string>
#include <map>
#include "Log.h"

class HttpRequestPack
{
public:
	HttpRequestPack()
		:m_headerParsed(false),m_tempBuffer(new std::string()),m_BodyIndex(-1),m_Type(),m_ServerName(),m_serverPort(80),m_Path(),m_Version(),
		m_fullRequestUrl(),m_headers(),m_Body(NULL)
	{
	}
	
	~HttpRequestPack();

	bool IsValid();

	void AppendData(char*,char*);

	const std::string& Type()
	{
		return m_Type;
	}

	const std::string& Path()
	{
		return m_Path;
	}

	const std::string& ServerName()
	{
		return m_ServerName;
	}

	unsigned short ServerPort()
	{
		return m_serverPort;
	}

	const std::string& Version()
	{
		return m_Version;
	}

	const std::string& FullRequestUrl()
	{
		return m_fullRequestUrl;
	}

	const std::map<std::string,std::string>& Headers()
	{
		return m_headers;
	}

	char* Body()
	{
		return m_Body;
	}

	void InitializeRequestRange(long long &min,long long &max);

	std::string& TempBuffer()
	{
		return *m_tempBuffer;
	}

	void SetTempBuffer(std::string *bufValue);

	void FreeTempBuffer();

private:
	static log4cplus::Logger log;

	void ParseHeader();

	void ParseHostAndPath();

	std::string::size_type BodySize();

	void CopyBody();

	bool m_headerParsed;

	std::string *m_tempBuffer;

	std::istringstream::pos_type m_BodyIndex;

	std::string m_Type;

	std::string m_ServerName;

	unsigned short m_serverPort;

	std::string m_Path;

	std::string m_Version;

	std::string m_fullRequestUrl;

	std::map<std::string,std::string> m_headers;

	char *m_Body;
};

#endif 